{include file="header.html"}
<body class="gr">

<div class="navBar">
	<div class="titleView">发现</div>
	<a class="right" href="wap.php?tpl=article.edit"><i class="article-edit"></i></a>
</div>

<div class="article-index main-top main-padding-bottom">
	<div class="pullRefresh">
		{if count($data.flashes)>0}
		<div class="pageView">
			<div class="slide">
				<ul>
					{foreach from=$data.flashes name=g item=g}
					<li ad_type="{$g->ad_type}" ad_content="{$g->ad_content}" pic="{$g->pic}"></li>
					{/foreach}
				</ul>
			</div>
			<div class="pager"></div>
		</div>
		{/if}
		
		{if count($data.articles)>0}
		<ul class="list">
			{foreach from=$data.articles name=g item=g}
			<li>
				<a href="wap.php?app=article&act=detail&id={$g->id}&discover=1">
					<div class="title"><div>{$g->add_time}</div>{$g->title}</div>
					<div class="content">{str_replace(PHP_EOL, '', preg_replace('/<\/?[^>]+>/', '', $g->content))}</div>
					{if is_array($g->pics)}
					<ul class="ge-bottom ge-light">
						{foreach from=$g->pics name=e item=e}
						<li style="background-image:url({$e->pic});"></li>
						{/foreach}
						<div class="clear"></div>
					</ul>
					{/if}
					<div class="bottom">
						<i></i><span>{$g->likes}</span>
						<i class="comments"></i><span>{$g->comments}</span>
					</div>
				</a>
			</li>
			{/foreach}
		</ul>
		{/if}
	</div>
</div>

<div class="footer">
	<a class="ico1" href="wap.php"></a>
	<a class="ico2" href="wap.php?app=category&act=index"></a>
	<a class="ico3 this" href="wap.php?app=article&act=index"></a>
	<a class="ico4 badge" href="wap.php?app=cart&act=index"><div>{if $cart_notify>0}<sub><b>{$cart_notify}</b></sub>{/if}</div></a>
	<a class="ico5" href="wap.php?app=member&act=index"></a>
</div>

{include file="footer.html"}
<script>
var offset = $('.pullRefresh .list > li').length;
function createHtml(g){
	var html = '<li>\
		<a href="wap.php?app=article&act=detail&id='+g.id+'&discover=1">\
			<div class="title"><div>'+g.add_time+'</div>'+g.title+'</div>\
			<div class="content">'+g.content.replace(/<\/?[^>]+>/g, '').replace(/(\n)+|(\r\n)+/g, '')+'</div>';
			if($.isArray(g.pics)){
			html += '<ul class="ge-bottom ge-light">';
				for(var i=0; i<g.pics.length; i++)html += '<li style="background-image:url('+g.pics[i].pic+');"></li>';
				html += '<div class="clear"></div>\
			</ul>';
			}
			html += '<div class="bottom">\
				<i></i><span>'+g.likes+'</span>\
				<i class="comments"></i><span>'+g.comments+'</span>\
			</div>\
		</a>\
	</li>';
	offset++;
	return html;
}
function setPics(){
	$('.list a ul').each(function(){
		var _this = $(this);
		if(!!_this.data('changedSize'))return true;
		_this.data('changedSize', true);
		var li = _this.find('li'), width = (_this.outerWidth(true)-10*4) / 3;
		li.css({ width:width, height:width }).loadbackground();
	});
}
function resize(){
	$('.pageView').autoHeight(320, 137);
	$('.pageView li').css({ width:$('.pageView').width(), height:$('.pageView').height() });
	$('.pageView').touchmove({
		pager : '.pager',
		drag : true,
		auto : 4000,
		autoWait : 4000,
		complete : function(){
			$('.pager').css('margin-left', -$('.pager').width()/2);
			setAds('.pageView .slide li');
		}
	});
}
$(window).resize(resize);
$(function(){
	resize();
	setAds('.pageView .slide li');
	setPics();
	$('.navBar .right').checklogin();
	$('.article-index').height($.window().height-$('.article-index').padding().bottom);
	$('.pullRefresh').pullRefresh({
		header : true,
		footer : true,
		footerNoMoreText : '- END -',
		refresh : function(fn){
			var _this = this;
			offset = 0;
			$.getJSON('api.php?app=article&act=index', function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data.articles))for(var i=0; i<json.data.articles.length; i++)html += createHtml(json.data.articles[i]);
				_this.find('.list').html(html);
				setPics();
				fn();
			});
		},
		load : function(fn){
			var _this = this;
			$.getJSON('api.php?app=article&act=index', { offset:offset }, function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data.articles))for(var i=0; i<json.data.articles.length; i++)html += createHtml(json.data.articles[i]);
				_this.find('.list').append(html);
				setPics();
				fn();
			});
		}
	});
});
</script>